<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--准备好一个“容器”-->
<div id="test"></div>

<!--引入react核心库-->
<script type="text/javascript" src="../js/react.development.js"></script>
<!--引入react-dom，用于支持react操作DOM -->
<script type="text/javascript" src="../js/react-dom.development.js"></script>
<!--引入babel，用于将jsx转为js -->
<script type="text/javascript" src="../js/babel.min.js"></script>

<script type="text/javascript" src="../js/prop-types.js"></script>

<script type="text/babel">
    class A extends React.Component {
        state = {carName: '奔驰'}

        changeCar = () => {
            this.setState({carName: '奥迪'})
        }

        render() {
            return (
                <div>
                    <div>A</div>
                    <button onClick={this.changeCar}>换车</button>
                    <B carName={this.state.carName}></B>
                </div>
            )
        }
    }

    class B extends React.Component {
        componentWillReceiveProps(props) {
            console.log('B---componentWillReceiveProps', props)
        }

        shouldComponentUpdate() {
            console.log('B---sholdComponentUpdate')
            return true
        }

        componentWillUpdate() {
            console.log('B---componentWillUpdate')
        }

        componentDidUpdate() {
            console.log('B---componentDidUpdate')
        }

        render() {
            console.log('B---render')
            return (
                <div>我是B组件,接收到的车是:{this.props.carName}</div>
            )
        }
    }

    //2.渲染组件到页面
    ReactDOM.render(<A></A>, document.getElementById('test'))
</script>
</body>
</html>

